home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 11 / Mac Magazin and MacEasy Magazine CD - Issue 11.iso / Sharewarebibliothek / Entwickler / appe Windows 2.0 / patches.c < prev    next >
Text File  |  1995-07-04  |  3KB  |  88 lines

  1. // File "patches.c" -
  2.  
  3. #include <Traps.h>
  4.  
  5. #include "main.h"
  6. #include "patches.h"
  7.  
  8. // ***********************************************************************************
  9. // Global Declarations 
  10.  
  11. ExitToShellUPP gSaveExitToShell;
  12.  
  13. ExitToShellUPP gExitToShellPatch=0;
  14. NewWindowUPP gNewWindowPatch=0;
  15.  
  16. // ***********************************************************************************
  17. // ***********************************************************************************
  18.  
  19. void PatchExitToShell() {
  20.     short trap = _ExitToShell; 
  21.     
  22.     if (! gExitToShellPatch) gExitToShellPatch = NewExitToShellProc(MyExitToShell);
  23.     if (! gExitToShellPatch) return;
  24.     
  25.     gSaveExitToShell = (ExitToShellUPP) 
  26.             NGetTrapAddress(trap, (trap & 0x0800) ? ToolTrap : OSTrap);
  27.     NSetTrapAddress((UniversalProcPtr) gExitToShellPatch,
  28.             trap, (trap & 0x0800) ? ToolTrap : OSTrap);
  29.     }
  30.     
  31. // ***********************************************************************************
  32. // ***********************************************************************************
  33.  
  34. pascal void MyExitToShell() {
  35.     static Boolean done = FALSE;
  36.     long saveA5;
  37.     ExitToShellUPP tempSaveExitToShell;
  38.     
  39.     // Setup (68k) globals in case we are ES-ing from deep within Macsbug.
  40.     saveA5 = SetCurrentA5();
  41.  
  42.     // Our ExitToShell() patch may cause re-entrancy problems... so we bracket
  43.     //   the functional calls by checking and setting a one-time flag.
  44.     if (! done) {
  45.         done = TRUE;
  46.         DoDispose();
  47.         }
  48.  
  49.     // Save off the global pointer while we still have our 68K A5-World set up
  50.     tempSaveExitToShell = gSaveExitToShell;
  51.     SetA5(saveA5);
  52.     
  53.     CallExitToShellProc(tempSaveExitToShell);
  54.     }
  55.  
  56. // ***********************************************************************************
  57. // ***********************************************************************************
  58.  
  59. void PatchNewWindow() {
  60.     short trap = _NewWindow; 
  61.  
  62.     if (! gNewWindowPatch) gNewWindowPatch = NewNewWindowProc(MyNewWindow);
  63.     if (! gNewWindowPatch) return;
  64.     
  65.     NSetTrapAddress((UniversalProcPtr) gNewWindowPatch,
  66.             trap, (trap & 0x0800) ? ToolTrap : OSTrap);
  67.     }
  68.     
  69. // ***********************************************************************************
  70. // ***********************************************************************************
  71.  
  72. pascal WindowPtr MyNewWindow(Ptr wStorage, Rect *bounds, StringPtr title,
  73.         Boolean vis, short procID, WindowPtr behind, Boolean close, long refCon) {
  74.     short trap = _NewCWindow;
  75.     WindowPtr win;
  76.     NewWindowUPP myNewCWindow;
  77.     
  78.     // Call NewCWindow in place of NewWindow!
  79.     myNewCWindow = (NewWindowUPP) 
  80.             NGetTrapAddress(trap, (trap & 0x0800) ? ToolTrap : OSTrap);
  81.     
  82.     win = CallNewWindowProc(myNewCWindow, wStorage, bounds, title, vis, procID,
  83.             behind, close, refCon);
  84.  
  85.     return(win);
  86.     }
  87.  
  88.